<?php
class User extends AppModel {
	var $name = 'User';
	
	//validate
	var $validate = array
					(
						'username' => array('rule'=>'/^[a-z0-9]{6,40}$/i', 'message'=>'Username must have 6 to 40 characters'),
						'password' => array('rule'=>'notEmpty', 'message'=>'This field cannot be left blank'),
						'email' => array('rule'=>'email', 'message'=>'Please suppy a valid email address')
					);
	//mac dinh phuong thuc ma hoa la sha1
	//doi sang ma hoa md5
	/*
	function hassPasswords($data)
	{
		if (isset($data['User']['password']))
		{
			$data['User']['password'] = md5($data['User']['password']);
			return $data;
		}
		return $data;
	}
	
	//cac thao tac thuc hien truoc khi validate
	function beforeValidate()
	{
		if (!$this->id)		//id chua co' => truong hop them moi
		{
			if ($this->findByUsername($this->data['User']['username']))
			{
				$this->invalidate('username_unique');
				return false;
			}
			
		}
		return true;
	}*/
    
    //-------- Check Useranme
    // function checkUsername(){
        // if(isset($this->data[$this->name]['id'])){
            // $where = array(
                            // "id !=" => $this->data[$this->name]['id'],
                            // "username" => $this->data[$this->name]['username'],
                            // ); 
                 
        // }
        // else{
            // $where = array(
                            // "username" => $this->data[$this->name]['username'],
                            // );  
        // } 
        // $this->find($where);
        // $count = $this->getNumRows();
        // if($count!=0){
            // return false;
        // }
        // else{
            // return true;
        // }
    // }
    
    //--- HashPassword
    // function hashPassword($data){
        // if(isset($this->data['User']['pass'])){
            // $this->data['User']['password'] = Security::hash($this->data['User']['pass'],NULL,TRUE);
            // return $data;
        // }
        // return $data;
    // }
    //----- beforeSave
    // function beforeSave(){
        // $this->hashPassword(NULL,TRUE);
        // return TRUE;
    // } 
    
}
?>